** This do.file measures changes across broad bins of the income distribution **
cd "D:\Dropbox\unequal_gains\QJE revision plan\analysis\

use ipums_feb2018, clear

keep hhwt serial hhincome year cpi99
duplicates drop
drop if hhincome<0 | hhincome==9999999

* keep years 2000-2004 & 2012-2016
keep if inrange(year,2000,2004) | inrange(year,2012,2016)
gen period=.
replace period=1 if inrange(year,2000,2004)
replace period=2 if inrange(year,2012,2016)

gen household_income=hhincome

gen income_quintile=.
* first quintile if makes below 20k
replace income_quintile=1 if household_income<=20000
* second quintile if makes between 20k & 40k
replace income_quintile=2 if household_income>20000 & household_income<40000
* third quintile if makes between 40k & 60k
replace income_quintile=3 if household_income>=40000 & household_income<60000
* fourth quintile if makes between 60k & 100k 
replace income_quintile=4 if household_income>=60000 & household_income<100000
* fifth quintile if makes above 100k
replace income_quintile=5 if household_income>=100000

gen total_income=hhwt*household_income

collapse (sum) hhwt total_income, by(period income_quintile)
gen avg_income=total_income/hhwt

tsset income_quintile period
gen double log_P=log(hhw)
gen double log_P_initial=L.log_P
gen double log_W=log(total_income)
gen double log_W_initial=L.log_P

gen g_n= log_P - L.log_P + log_W - L.log_W

drop if missing(g_n)
keep g_n income_quintile log_P log_P_initial log_W log_W_initial
gen g_n_annual=g_n/(2016-2004+1)

scatter g_n_annual income_quintile

save income_groups, replace






